package com.mxdx.edu.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.mxdx.edu.dao.VideoDao;
import com.mxdx.edu.service.IVideoService;

/**
 * 视频信息service
 *
 * @author howie
 */
@Service
public class VideoServiceImpl implements IVideoService {

	@Resource
	private VideoDao videoDao;

	@Override
	public Map<String, Object> findMapByVideoId(String videoId) {
		Map<String, Object> param = new HashMap<>();
		param.put("videoId", videoId);
		List<Map<String, Object>> list = videoDao.findListByMap(param);
		if(list != null && list.size() > 0){
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<Map<String, Object>> findListByMap(Map<String, Object> param) {
		return videoDao.findListByMap(param);
	}

	@Override
	public Integer videoStudentLimitBtMap(String studentId,String courseId,String semesterId,String videoId){

		Map<String, Object> param = new HashMap<>();

		param.put("studentId",studentId);
		param.put("courseId",courseId);
		param.put("semesterId",semesterId);
		param.put("videoId",videoId);

		return videoDao.videoStudentLimitBtMap(param) == null ? 0 : videoDao.videoStudentLimitBtMap(param);
	}

	@Override
	public int videoStudentSave(String id, String studentId, String courseId, String semesterId, String videoId, int timeMinute, int timeSecond, Date createDate, Date updateDate){

		Map<String, Object> param = new HashMap<>();

		param.put("id",id);
		param.put("studentId",studentId);
		param.put("courseId",courseId);
		param.put("semesterId",semesterId);
		param.put("videoId",videoId);
		param.put("timeMinute",timeMinute);
		param.put("timeSecond",timeSecond);
		param.put("createDate",createDate);
		param.put("updateDate",updateDate);

		return videoDao.videoStudentSave(param);
	}

	@Override
	public int videoStudentUpdate(String id,String studentId,String courseId,String semesterId,String videoId, Date updateDate){

		Map<String, Object> param = new HashMap<>();

		param.put("id",id);
		param.put("studentId",studentId);
		param.put("courseId",courseId);
		param.put("semesterId",semesterId);
		param.put("videoId",videoId);
		param.put("updateDate",updateDate);

		return videoDao.videoStudentUpdate(param);
	}

	@Override
	public int videoStudentDelete(String studentId,String courseId,String semesterId){

		Map<String, Object> param = new HashMap<>();

		param.put("studentId",studentId);
		param.put("courseId",courseId);
		param.put("semesterId",semesterId);

		return videoDao.videoStudentDelete(param);
	}

	@Override
	public int videoCourseLimitByMap(String courseId,String videoPacketId){

		Map<String, Object> param = new HashMap<>();
		param.put("courseId",courseId);
		param.put("videoPacketId",videoPacketId);
		Integer count = videoDao.videoCourseLimitByMap(param);
		return  count == null ? 0 : count.intValue();
	}


}
